'use strict';


import Base from './base.js';

const querystring = require('querystring');
var ttutil = require("../../business/ttutil");
var http = require('http');
const getToken = require('../../business/getwebtoken.js');
const getUserInfo = require('../../business/getwebuserinfo.js');
var Url = require("url");
var SqlPool = require('../../business/sql_pool.js');
export default class extends Base {

    
    async indexAction() {

        var arg = Url.parse(this.http.req.url, true).query;
        //console.log("arg======"+ this.http.req.url);
        var self = this;
        var postData = "";
        var Version =arg.version;
        var MerId = arg.merid;
        var TransNo = arg.transno;
        var OrderNo = arg.orderno;

        var OrderAmount = arg.orderamount;
        var TransAmount = arg.transamount;
        var Status = arg.status;
        var TransTime = arg.transtime;
        var Remark = arg.remark;
        var Sign = arg.sign;

        var Origin=Version+MerId+TransNo+OrderNo+OrderAmount+TransAmount+Status+TransTime+Remark;
        var mysign=ttutil.md5(Origin+"|AA9585A880EF0F8631A7D4CB0DDA6457").toUpperCase();
        //console.log("mysign:" +mysign);


        // var data = {
        //     version: arg.version,
        //     merid: arg.merid,     
        //     transno: arg.transno,
        //     orderno:arg.orderno,
        //     orderamount:arg.orderamount,
        //     transamount:arg.transamount,
        //     status:arg.status,
        //     transtime:arg.transtime,
        //     remark:arg.remark,
        //     sign:arg.sign
        // };

        // data = querystring.stringify(data);

        if (Status == "1"&&Sign==mysign) {
        //     http.get('http://47.105.56.254:16923/9pay/newNotifyUrl?' + data, (res) => {
        //         //console.log(`Got response: ${res.statusCode}`);
        //     //   // consume response body
        //        console.log("已发送充值回调数据数据");
        //    }).on('error', (e) => {
        //        console.log("向服务端发送信息充值回调数据发生错误  "+e);
              
        //    });
            SqlPool.x_query('CALL ps_mark_pay_to_payed(?,?,?);', [arg.orderno, arg.transno, ""], function (err, rows, fields) {
                if (err) {
                    return;
                }
            });
        }
        this.http.res.end("OK");
        return;
    }
}